package com.qianfeng.smartmetting.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qianfeng.smartmetting.entity.Room;
import com.qianfeng.smartmetting.entity.User;
import com.qianfeng.smartmetting.service.RoomDao;
import com.qianfeng.smartmetting.service.UserDao;
import com.qianfeng.smartmetting.util.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

@RestController
public class TestController {

    @Autowired
    private RoomDao roomDao;

    @Autowired
    private UserDao userDao;

    @PostMapping("/hello/{id}")
    public String hello(@PathVariable("id") String msg){
        return msg;
    }

    @GetMapping("/test/list")
    public Map list(int page,int pagesize){
        Page<Room> page1 = new Page<>(page,pagesize);
        IPage<Room> obj = roomDao.page(page1);
        return CommonResult.ok("查询成功",obj);
    }

    @PutMapping("/test/{id}")
    public Map add(@PathVariable("id") Integer id, Room room){
        Map map = new HashMap();
        room.setRoomId(id);
        map.put("data",roomDao.updateById(room));
        return map;
    }

    @PostMapping("/test/modify")
    public Map modify(@RequestBody Room room){
        System.out.println(room.getRoomId());
        Map map = new HashMap();
        map.put("data",roomDao.updateById(room));
        return map;
    }

    @PostMapping("/test/delete")
    public Map deleteMore(@RequestBody String[] ids){
        Map map = new HashMap();
        map.put("data",roomDao.removeByIds(Arrays.asList(ids)));
        return map;
    }


}
